
libname inn 'D:\Amazon Price Dynamics\New Data\Data Scraped\Home_Kitchen\Cluster Analysis';
proc contents data =final_gam_modeldata;
run;

data focal_rival_prods23;
set inn.focal_rival_prods23ecooker;
run;
data final_gam_modeldata;
set inn.final_gam_modeldata_ecooker;
run;
proc print data = eliteplat_sales;
run;

data eliteplat_ecooker;
set focal_rival_prods23;
/**only Breville and Elite Platinum ASINs for example**/
/**Elite Platinum: B0051O92U4**/
/**Breville: B013I40R8E**/ 
/**Crock Pot: B003HF6PUO**/
where ASIN in ('B0051O92U4');
run;
data breville_ecooker;
set focal_rival_prods23;
/**only Breville and Elite Platinum ASINs for example**/
/**Elite Platinum: B0051O92U4**/
/**Breville: B013I40R8E**/ 
where ASIN in ('B013I40R8E');
run;
data crockp_ecooker;
set focal_rival_prods23;
/**only Breville and Elite Platinum ASINs for example**/
/**Elite Platinum: B0051O92U4**/
/**Breville: B013I40R8E**/ 
/**Crock Pot: B003HF6PUO**/
where ASIN in ('B003HF6PUO');
run;
proc sort data = eliteplat_ecooker (keep = time1 Sales_Rank_Own_Categ) nodupkey out= eliteplat_sales;
by time1;
run;

proc sort data = breville_ecooker (keep = time1 Sales_Rank_Own_Categ) nodupkey out= breville_sales;
by time1;
run;
proc sort data = crockp_ecooker (keep = time1 Sales_Rank_Own_Categ) nodupkey out= crockp_sales;
by time1;
run;
proc sort data = final_gam_modeldata (keep = time1 buyboxprice_EP 
buyboxprice_EP_lag1 priceAmzn_EP priceAmzn_EP_lag priceclust2_EP priceclust2_EP_lag)
nodupkey out = ep_modeldata1;
by time1;
run;

proc sort data = final_gam_modeldata (keep = time1 buyboxprice_breville 
buyboxprice_brv_lag1 priceAmzn_Breville priceAmzn_Brev_lag priceclust4_Breville priceclust4_Brev_lag)
nodupkey out = brev_modeldata1;
by time1;
run;
proc contents data = final_gam_modeldata;
run;
proc sort data = final_gam_modeldata (keep = time1 buyboxprice_crockp 
buyboxprice_crockp_lag1 priceAmzn_CrockP priceAmzn_CrockP_lag priceclust3_CrockP priceclust3_CrockP_lag
priceclust5_CrockP priceclust5_CrockP_lag)
nodupkey out = crockp_modeldata1;
by time1;
run;

/**merging with modeling data set**/
data eliteplat_salesreg;
merge eliteplat_sales (in=a) ep_modeldata1 (in=b);
by time1;
if a and b;
run;

data breville_salesreg;
merge breville_sales (in=a) brev_modeldata1 (in=b);
by time1;
if a and b;
run;

data crockp_salesreg;
merge crockp_sales (in=a) crockp_modeldata1 (in=b);
by time1;
if a and b;
run;


proc contents data = focal_rival_prods24;
run;
proc print data = focal_rival_prods24 (obs=30);
var Sales_Rank_Own_Categ;
where ASIN in ('B0051O92U4');
run;

/**using junglescout estimator: sales rank to monthly sales in home and kitchen**/
/***https://www.junglescout.com/estimator/**/
/**monthly sales  @ rank 1900 = 5700, @ rank 2000 = 5520**/
/**monthly sales  @ rank 2100 = 5370, @ rank 3000 = 4260**/
/**monthly sales  @ rank 3100 = 4170, @ rank 5000 = 3000**/
/**monthly sales  @ rank 5100 = 2970, @ rank 7000 = 2370**/
/**monthly sales  @ rank 7100 = 2340, @ rank 9000 = 1950**/
/**monthly sales  @ rank 9100 = 1920, @ rank 12000 = 1560**/
/**monthly sales  @ rank 13000 = 1470, @ rank 14000 = 1380**/
/**monthly sales  @ rank 13000 = 1470, @ rank 14000 = 1380**/
/**monthly sales @ rank 15000 = 1290, @ rank 16000 = 1230**/
/**monthly sales @ rank 17000 = 1170, @ rank 18000 = 1110**/
/**monthly sales  @ rank 19000 = 1050, @ rank 20000 = 1020**/
/**monthly sales  @ rank 21000 = 960, @ rank 22000 = 930**/
/**monthly sales  @ rank 23000 = 900,**/

data modelsales_estimator;
input sales_rank monthly_sales;
cards;
1900 5700
2000 5520
2100 5370
3000 4260
3100 4170
5000 3000
5100 2970
7000 2370
7100 2340
9000 1950
9100 1920
12000 1560
13000 1470
14000 1380
15000 1290
16000 1230
17000 1170
18000 1110
19000 1050
20000 1020
21000 960
22000 930
23000 900
;
run;
data model_dailysales_estimator;
set modelsales_estimator;
daily_sales = monthly_sales/30;
Y = log(daily_sales + 1);
X = log(sales_rank);
run;
/**using Ghose and Sundarajan's model for demand (Q) - sales rank conversion**/
/**log(Q+1) = log(alpha) + beta*log(sales rank)**/
proc reg data = model_dailysales_estimator;
 model Y = X;
 run;
/**our model gives the following estimates:
 log(alpha) = 10.82981, beta = -0.73292 **/

proc contents data = totsales_brev;
run;

data totsales_ep;
set eliteplat_salesreg;
daily_sales_ep = exp(10.82981 - 0.73292*log(Sales_Rank_Own_Categ)) -1;
RUN;
data totsales_brev;
set breville_salesreg;
daily_sales_brev = exp(10.82981 - 0.73292*log(Sales_Rank_Own_Categ)) -1;
RUN;

data totsales_crockp;
set crockp_salesreg;
daily_sales_crockp = exp(10.82981 - 0.73292*log(Sales_Rank_Own_Categ)) -1;
RUN;


/**modeling sales as a function of buy box price - current and 1 period lag***/

/***ELITE PLAT****/

proc reg data = totsales_ep;
model daily_sales_ep = 
buyboxprice_EP
buyboxprice_EP_lag1
;
run;


/***BREVILLE****/
proc reg data = totsales_brev;
model daily_sales_brev = 
buyboxprice_breville
buyboxprice_brv_lag1;
run;

/**CROCK POT***/

proc reg data = totsales_crockp;
model daily_sales_crockp = 
buyboxprice_crockp
buyboxprice_crockp_lag1
;
run;
